const {
  $util,
} = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    hasMore: true,
    list: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(ops) {
    let year = new Date().getFullYear();
    this.setData({
      year: year,
      curYear: year,
    }, () => {
      this.loadList();
      wx.setNavigationBarTitle({
        title: '党建历程',
      });
    });
  },
  bindYearChange(e) {
    this.setData({
      year: e.detail.value,
      page: 1,
    }, () => {
      this.loadList();
    });
  },
  loadList() {
    const {
      page,
      list: d_list,
      year,
    } = this.data;
    $util.request({
      url: 'entry/wxapp/partylife.partycourse.getpcourselist',
      data: {
        page,
        year,
      },
      success: (res) => {
        let list = res.list;
        if (page > 1) {
          list = [...d_list, ...list];
        }
        this.setData({
          list,
          hasMore: list.length > 0,
          page: page + 1,
        });
      },
    });
  },
  onReachBottom() {
    this.data.hasMore && this.loadList();
  },
  onShareAppMessage() {},
});